$(document).ready(function(){
	$(".love-button").on("click",function(){
		judge($(this));
	});

	$(".adore-button").on("click",function(){
		judge($(this));
	});

	$(".friend-button").on("click",function(){
		judge($(this));
	});

	$(".leave-button").on("click",function(){
		judge($(this));
	});

});

var words =5;
	$("input[name='lover_poem']").change(function(){
		var poem_type = $("input:radio[name='lover_poem']:checked").next().text();
		if(poem_type == "五言"){
			words = 5;
		}else{
			words = 7;
		}
	})
	$("input:radio[name='friend-poem']").change(function(){
		var poem_type = $("input[name='friend-poem']:checked").next().text();
		if(poem_type == "五言"){
			words = 5;
		}else{
			words = 7;
		}
	})

function judge(zj){
	console.log(zj.text())

	var sents;
	if($(".weui_tab_bd_item_active .weui_input").val().replace(/[ ]/g,"").length<2||$(".weui_input").val().replace(/[ ]/g,"").length>8){
		$.alert("请输入2-8字的尊称");
		return;
	}
	
	if($(".weui_tab_bd_item_active .weui_input").val().replace(/[ ]/g,"").length<=4){
		sents = 4;
	}else{
		sents = 8;
	}
	$(".index-wrapper").css("opacity",0);
	$.showLoading("鸭鸭在挥墨泼亳中...");
	var data ={
		'words':words,
		'sents':sents,
		'title':zj.text(),
		'heads':$(".weui_tab_bd_item_active .weui_input").val().replace(/[ ]/g,""),
		'times':1
	}
	var post_data = JSON.stringify(data);
	//var url = "http://cqa.iflytek.com/zb/poem?callback=?";
	// var url = "http://192.168.86.4:10063/poem?callback=?";
	// 				$.getJSON(url, {
	// 					data: post_data
	// 				}, function(json, success) {
	// 					var jsonData = eval(json);
	// 					if (jsonData == null) {
	// 						$.alert("好像失败了！");
	// 					}
	// 					window.location.href ="make.html";
	// 					// server_time = jsonData["server_time"].toFixed(3);
	// 					// var items = jsonData["result_list"].toString().split("\n").toString().split(",");
	// 					// for (var i = 0; i < items.length; i++) {
	// 					// 	var charArr = items[i].split('');
	// 					// 	charArr[0] = '<red>' + charArr[0] + '</red>';
	// 					// 	items[i] = charArr.join('');
	// 					// 	$('#poem').append('<p>' + items[i] + '</p>');
	// 					// }
	// 					// $('#writing').css('display', 'none');
	// 					// $('.page3').css('display', 'block');
	// 				});

	$.ajax({
		url:'http://192.168.86.4:10063/zb/poem?data='+post_data,
		type:'get',
		//data:post_data,
		// dataType:'jsonp',
		// jsonp:'callback',
		success:function(data){
			get_data = JSON.parse(data);
			var poem_con = get_data.result_text;
			window.location.href ="make.html?poem_type="+words+"&poem_sens="+sents+"&poem_con="+poem_con;
			$.hideLoading();
		},error:function(data){
			$.hideLoading();
		 	$.alert("人气太旺,请稍后...");
		    $.alert("鸭鸭词穷了~~换个词吧~");
		}
	})
}

